<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var minimumDeviation = function (nums) {
            //思路：让最小值尽可能大，让最大值尽可能小
            // 由于增大只有奇数才能够进行，因而先对所有奇数*2
            // 然后对偶数进行尽可能小
            let set = new Set();
            for (num in nums) {
                set.add(nums[num] % 2 == 0 ? nums[num] : nums[num] * 2);
            }
            let res = Math.max(...set) - Math.min(...set);

            while (res > 0 && Math.max(...set) % 2 == 0) {
                let val = Math.max(...set);
                set.delete(val);
                set.add(val / 2);
                res = Math.min(res, Math.max(...set) - Math.min(...set));
            }
            return res;
        };
        console.log(minimumDeviation([2, 10, 8]));//3


    </script>
</body>

</html>